package com.mystudy.train.member.controller;

import com.mystudy.train.common.exception.BusinessExceptionEnum;
import com.mystudy.train.common.resp.CommonResp;
import com.mystudy.train.member.req.MemberLoginReq;
import com.mystudy.train.member.req.MemberRegisterReq;
import com.mystudy.train.member.req.MemberSendCodeReq;
import com.mystudy.train.member.service.MemberService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.mystudy.train.member.resp.MemberLoginResp;

/**
 * @author SaoE
 * @date 2025/1/7 22:02
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    private MemberService memberService;

    @GetMapping("/count")
    public CommonResp<Integer> count() {
        CommonResp<Integer> commonRespo = new CommonResp<>();
        commonRespo.setContent(memberService.count());
        return commonRespo;
    }

    @PostMapping("/register")
    public CommonResp<Long> register(@Valid @RequestBody MemberRegisterReq memberRegisterReq) {
        return new CommonResp<>(BusinessExceptionEnum.OPERATION_SUCCESS.getDesc(), memberService.register(memberRegisterReq));
    }

    @PostMapping("/send-code")
    public CommonResp register(@Valid @RequestBody MemberSendCodeReq memberSendCodeReq) {
        memberService.MemberSendCode(memberSendCodeReq);
        return new CommonResp(BusinessExceptionEnum.OPERATION_SUCCESS.getDesc(), null);
    }

    @PostMapping("/login")
    public CommonResp<MemberLoginResp> login(@Valid @RequestBody MemberLoginReq memberLoginReq) {
        MemberLoginResp resp = memberService.login(memberLoginReq);
        return new CommonResp(BusinessExceptionEnum.OPERATION_SUCCESS.getDesc(), resp);
    }

}
